﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Collections;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Windows.Controls.Primitives;
using System.Windows.Media.Imaging;

namespace CricketHub
{

    public partial class Teams : PhoneApplicationPage
    {
        TeamRequestingData tdata = new TeamRequestingData();
        public Teams()
        {
            InitializeComponent();
            tdata.team = this;
            tdata.Request();
            teamspbr.Visibility = Visibility.Visible;
        //   list_players.SelectionChanged+=new SelectionChangedEventHandler(list_players_SelectionChanged);
        }
        List<Testcrick> testcri = new List<Testcrick>();
        List<Odcrick> odcri = new List<Odcrick>();
        List<T20> twenty = new List<T20>();
      //  List<Playernames> plys = new List<Playernames>();
        public List<Dictionary<string, string>> team_players_names = new System.Collections.Generic.List<System.Collections.Generic.Dictionary<string, string>>();
       // public Dictionary<string, string> plys_mems = new System.Collections.Generic.Dictionary<string, string>();

        private void list_players_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
           int index= list_players.SelectedIndex;
           string dd = player_names.ElementAt(index).ToString();
           App a = App.Current as App;
           a.player_id = dd;
            NavigationService.Navigate(new Uri("/PlayerDetails.xaml",UriKind.RelativeOrAbsolute));
            pppp.IsOpen = false;
 
        }


        public void Update(string xmldata)
        {
            var element = XElement.Parse(xmldata);
            var count = element.Descendants("team-profile").Count();
            System.Diagnostics.Debug.WriteLine("number of teams...."+count);
            for (int i = 0; i < count; i++)
            {
                var size = element.Descendants("team-profile").ElementAt(i);
                var nxtelement = size.Descendants("stats").ElementAt(0);//.Attribute("type").Value;
                Testcrick obj = new Testcrick();
                obj.span = nxtelement.Element("span").Value;
                obj.match = nxtelement.Element("matches").Value;
                obj.won = nxtelement.Element("won").Value;
                obj.lost = nxtelement.Element("lost").Value;
                obj.tied = nxtelement.Element("tied").Value;
                obj.draw = nxtelement.Element("draw").Value;
                obj.percentage = nxtelement.Element("percentage").Value;
                testcri.Add(obj);
                System.Diagnostics.Debug.WriteLine("stats type is....................." + nxtelement);
                System.Diagnostics.Debug.WriteLine("span value is........." + obj);
                var nxtelement1 = size.Descendants("stats").ElementAt(1);//.Attribute("type").Value;
               // Odcrick od = new Odcrick();
                Odcrick od = new Odcrick();
                od.span = nxtelement1.Element("span").Value;
                od.match = nxtelement1.Element("matches").Value;
                od.won = nxtelement1.Element("won").Value;
                od.lost = nxtelement1.Element("lost").Value;
                od.tied = nxtelement1.Element("tied").Value;
                od.draw = nxtelement1.Element("draw").Value;
                od.percentage = nxtelement1.Element("percentage").Value;
                odcri.Add(od);
                System.Diagnostics.Debug.WriteLine("od matches,,,,,,,,,," + od);
                var nxtelement2 = size.Descendants("stats").ElementAt(2);

                T20 tw = new T20();
                tw.span = nxtelement2.Element("span").Value;
                tw.matches = nxtelement2.Element("matches").Value;
                tw.won = nxtelement2.Element("won").Value;
                tw.lost = nxtelement2.Element("lost").Value;
                tw.tied = nxtelement2.Element("tied").Value;
                tw.draw = nxtelement2.Element("draw").Value;
                tw.percentage = nxtelement2.Element("percentage").Value;
                twenty.Add(tw);
                System.Diagnostics.Debug.WriteLine("twenty twenty matches data..." + twenty.Count);
                var squard = size.Descendants("squad").Elements("player").Count();
                System.Diagnostics.Debug.WriteLine("count for player tag...." + squard);
                var player=size.Descendants("squad").ElementAt(0);
                Playernames play = new Playernames();
                Dictionary<string, string> plys_mems = new System.Collections.Generic.Dictionary<string, string>();
                for (int sub = 0; sub < squard; sub++)
                {
                    
                    play.playername = player.Descendants("player").ElementAt(sub).LastAttribute.Value;
                   play.playerid = player.Descendants("player").ElementAt(sub).FirstAttribute.Value;
                  //  plys.Add(play);
                    try
                    {
                        plys_mems.Add(play.playerid,play.playername);//play.playerid
                       //team_players_names.ElementAt(i).Add(play.playerid, play.playername);
                    }
                    catch (Exception ee)
                    {
                        System.Diagnostics.Debug.WriteLine("value as an value is...################################################################################################......"+plys_mems.Count);
                    }
                }
               // System.Diagnostics.Debug.WriteLine("count for players......."+plys.Count);
                //team_players_names.Add(plys_mems);
                System.Diagnostics.Debug.WriteLine("................count for team_players_names is............." + team_players_names.Count);
                team_players_names.Add(plys_mems);
               
                
            }
            Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    teamspbr.Visibility = Visibility.Collapsed;
                    p.IsOpen = true;
                    button1.Background = new SolidColorBrush(Colors.DarkGray);

                    try
                    {
                        button2.Background = new SolidColorBrush(Colors.Green);
                        button1.Background = new SolidColorBrush(Colors.DarkGray);
                        button3.Background = new SolidColorBrush(Colors.Green);
                        button4.Background = new SolidColorBrush(Colors.Green);
                        button1.Background = new SolidColorBrush(Colors.DarkGray);
                        App cuntry = App.Current as App;
                        int index_c = cuntry.country_selcted;
                        pppp.IsOpen = false;
                        p2.IsOpen = false;
                        p1.IsOpen = false;
                        p.IsOpen = true;
                        Border border = new Border();
                        border.BorderBrush = new SolidColorBrush(Colors.Black);
                        border.BorderThickness = new Thickness(5.0);
                        //border.Height = 100;
                        // border.Width = 200;
                        border.Margin = new Thickness(40, 250, 0, 0);
                        StackPanel panel = new StackPanel();
                        panel.Height = 450;
                        panel.Width = 400;
                        panel.Background = new SolidColorBrush(Colors.LightGray);
                        Testcrick tea;
                        tea = testcri.ElementAt(index_c);
                        TextBlock span = new TextBlock();
                        span.Name = "span";
                        span.Text = "SPAN";
                        span.FontSize = 26;
                        span.HorizontalAlignment = HorizontalAlignment.Left;
                        span.Margin = new Thickness(26, 30, 0, 0);
                        TextBlock span_value = new TextBlock();
                        span_value.Name = "span_value";
                        span_value.Text = tea.span;
                        span_value.FontSize = 26;
                        span_value.HorizontalAlignment = HorizontalAlignment.Right;
                        span_value.Margin = new Thickness(0, -40, 23, 0);
                        //span_value.VerticalAlignment = VerticalAlignment.Top;
                        TextBlock matches = new TextBlock();
                        matches.Name = "matches";
                        matches.Text = "MATCHES";
                        matches.FontSize = 26;
                        matches.Margin = new Thickness(26, 30, 0, 0);
                        matches.HorizontalAlignment = HorizontalAlignment.Left;
                        TextBlock matches_value = new TextBlock();
                        matches_value.Name = "matches_value";
                        matches_value.Text = tea.match;
                        matches_value.FontSize = 26;
                        matches_value.Margin = new Thickness(0, -35, 23, 0);
                        matches_value.HorizontalAlignment = HorizontalAlignment.Right;
                        TextBlock won = new TextBlock();
                        won.Name = "won";
                        won.Text = "WON";
                        won.FontSize = 26;
                        won.Margin = new Thickness(26, 30, 0, 0);
                        won.HorizontalAlignment = HorizontalAlignment.Left;
                        TextBlock won_value = new TextBlock();
                        won_value.Name = "won_name";
                        won_value.Text = tea.won;
                        won_value.FontSize = 26;
                        won_value.Margin = new Thickness(0, -35, 23, 0);
                        won_value.HorizontalAlignment = HorizontalAlignment.Right;
                        TextBlock lost = new TextBlock();
                        lost.Name = "lost";
                        lost.Text = "Lost";
                        lost.HorizontalAlignment = HorizontalAlignment.Left;
                        lost.FontSize = 26;
                        lost.Margin = new Thickness(26, 30, 0, 0);
                        TextBlock lost_val = new TextBlock();
                        lost_val.Name = "lost_valu";
                        lost_val.Text = tea.lost;
                        lost_val.FontSize = 26;
                        lost_val.Margin = new Thickness(0, -35, 23, 0);
                        lost_val.HorizontalAlignment = HorizontalAlignment.Right;
                        TextBlock tired = new TextBlock();
                        tired.Name = "tired";
                        tired.Text = "TIRED";
                        tired.FontSize = 26;
                        tired.Margin = new Thickness(26, 30, 0, 0);
                        tired.HorizontalAlignment = HorizontalAlignment.Left;
                        TextBlock tired_val = new TextBlock();
                        tired_val.Name = "tired_val";
                        tired_val.Text = tea.tied;
                        tired_val.FontSize = 26;
                        tired_val.Margin = new Thickness(0, -35, 23, 0);
                        tired_val.HorizontalAlignment = HorizontalAlignment.Right;
                        TextBlock draw = new TextBlock();
                        draw.Name = "draw";
                        draw.Text = "DRAW";
                        draw.FontSize = 26;
                        draw.Margin = new Thickness(26, 30, 0, 0);
                        draw.HorizontalAlignment = HorizontalAlignment.Left;
                        TextBlock draw_val = new TextBlock();
                        draw_val.Name = "draw_name";
                        draw_val.Text = tea.draw;
                        draw_val.FontSize = 26;
                        draw_val.Margin = new Thickness(0, -35, 23, 0);
                        draw_val.HorizontalAlignment = HorizontalAlignment.Right;
                        TextBlock perc = new TextBlock();
                        perc.Text = "PERCENTAGE";
                        perc.Name = "perc";
                        perc.FontSize = 26;
                        perc.Margin = new Thickness(26, 30, 0, 0);
                        perc.HorizontalAlignment = HorizontalAlignment.Left;
                        TextBlock perc_val = new TextBlock();
                        perc_val.Name = "perc_val";
                        perc_val.Text = tea.percentage;
                        perc_val.FontSize = 26;
                        perc_val.Margin = new Thickness(0, -35, 23, 0);
                        perc_val.HorizontalAlignment = HorizontalAlignment.Right;
                        panel.Children.Add(span);
                        panel.Children.Add(span_value);
                        panel.Children.Add(matches);
                        panel.Children.Add(matches_value);
                        panel.Children.Add(won);
                        panel.Children.Add(won_value);
                        panel.Children.Add(lost);
                        panel.Children.Add(lost_val);
                        panel.Children.Add(tired);
                        panel.Children.Add(tired_val);
                        panel.Children.Add(draw);
                        panel.Children.Add(draw_val);
                        panel.Children.Add(perc);
                        panel.Children.Add(perc_val);
                        //StackPanel sta = new StackPanel();
                        list.Items.Add(panel);
                        // sta.Children.Add(list);
                        list.Height = 200;
                        list.Width = 350;

                        border.Child = panel;
                        p.Child = border;
                    }
                    catch (Exception ksd)
                    {
                        MessageBox.Show("Please wait it is loading and  try again ");
                    }








                });
 
        }
        Popup p = new Popup();
       public ListBox list = new ListBox();
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                button2.Background = new SolidColorBrush(Colors.Green);
                button1.Background = new SolidColorBrush(Colors.DarkGray);
                button3.Background = new SolidColorBrush(Colors.Green);
                button4.Background = new SolidColorBrush(Colors.Green);
                button1.Background = new SolidColorBrush(Colors.DarkGray);
                App cuntry = App.Current as App;
                int index_c = cuntry.country_selcted;
                pppp.IsOpen = false;
                p2.IsOpen = false;
                p1.IsOpen = false;
                p.IsOpen = true;
                Border border = new Border();
                border.BorderBrush = new SolidColorBrush(Colors.Black);
                border.BorderThickness = new Thickness(5.0);
                //border.Height = 100;
                // border.Width = 200;
                border.Margin = new Thickness(40, 250, 0, 0);
                StackPanel panel = new StackPanel();
                panel.Height = 450;
                panel.Width = 400;
                panel.Background = new SolidColorBrush(Colors.LightGray);
                Testcrick tea;
                tea = testcri.ElementAt(index_c);
                TextBlock span = new TextBlock();
                span.Name = "span";
                span.Text = "SPAN";
                span.FontSize = 26;
                span.HorizontalAlignment = HorizontalAlignment.Left;
                span.Margin = new Thickness(26, 30, 0, 0);
                TextBlock span_value = new TextBlock();
                span_value.Name = "span_value";
                span_value.Text = tea.span;
                span_value.FontSize = 26;
                span_value.HorizontalAlignment = HorizontalAlignment.Right;
                span_value.Margin = new Thickness(0, -40, 23, 0);
                //span_value.VerticalAlignment = VerticalAlignment.Top;
                TextBlock matches = new TextBlock();
                matches.Name = "matches";
                matches.Text = "MATCHES";
                matches.FontSize = 26;
                matches.Margin = new Thickness(26, 30, 0, 0);
                matches.HorizontalAlignment = HorizontalAlignment.Left;
                TextBlock matches_value = new TextBlock();
                matches_value.Name = "matches_value";
                matches_value.Text = tea.match;
                matches_value.FontSize = 26;
                matches_value.Margin = new Thickness(0, -35, 23, 0);
                matches_value.HorizontalAlignment = HorizontalAlignment.Right;
                TextBlock won = new TextBlock();
                won.Name = "won";
                won.Text = "WON";
                won.FontSize = 26;
                won.Margin = new Thickness(26, 30, 0, 0);
                won.HorizontalAlignment = HorizontalAlignment.Left;
                TextBlock won_value = new TextBlock();
                won_value.Name = "won_name";
                won_value.Text = tea.won;
                won_value.FontSize = 26;
                won_value.Margin = new Thickness(0, -35, 23, 0);
                won_value.HorizontalAlignment = HorizontalAlignment.Right;
                TextBlock lost = new TextBlock();
                lost.Name = "lost";
                lost.Text = "Lost";
                lost.HorizontalAlignment = HorizontalAlignment.Left;
                lost.FontSize = 26;
                lost.Margin = new Thickness(26, 30, 0, 0);
                TextBlock lost_val = new TextBlock();
                lost_val.Name = "lost_valu";
                lost_val.Text = tea.lost;
                lost_val.FontSize = 26;
                lost_val.Margin = new Thickness(0, -35, 23, 0);
                lost_val.HorizontalAlignment = HorizontalAlignment.Right;
                TextBlock tired = new TextBlock();
                tired.Name = "tired";
                tired.Text = "TIRED";
                tired.FontSize = 26;
                tired.Margin = new Thickness(26, 30, 0, 0);
                tired.HorizontalAlignment = HorizontalAlignment.Left;
                TextBlock tired_val = new TextBlock();
                tired_val.Name = "tired_val";
                tired_val.Text = tea.tied;
                tired_val.FontSize = 26;
                tired_val.Margin = new Thickness(0, -35, 23, 0);
                tired_val.HorizontalAlignment = HorizontalAlignment.Right;
                TextBlock draw = new TextBlock();
                draw.Name = "draw";
                draw.Text = "DRAW";
                draw.FontSize = 26;
                draw.Margin = new Thickness(26, 30, 0, 0);
                draw.HorizontalAlignment = HorizontalAlignment.Left;
                TextBlock draw_val = new TextBlock();
                draw_val.Name = "draw_name";
                draw_val.Text = tea.draw;
                draw_val.FontSize = 26;
                draw_val.Margin = new Thickness(0, -35, 23, 0);
                draw_val.HorizontalAlignment = HorizontalAlignment.Right;
                TextBlock perc = new TextBlock();
                perc.Text = "PERCENTAGE";
                perc.Name = "perc";
                perc.FontSize = 26;
                perc.Margin = new Thickness(26, 30, 0, 0);
                perc.HorizontalAlignment = HorizontalAlignment.Left;
                TextBlock perc_val = new TextBlock();
                perc_val.Name = "perc_val";
                perc_val.Text = tea.percentage;
                perc_val.FontSize = 26;
                perc_val.Margin = new Thickness(0, -35, 23, 0);
                perc_val.HorizontalAlignment = HorizontalAlignment.Right;
                panel.Children.Add(span);
                panel.Children.Add(span_value);
                panel.Children.Add(matches);
                panel.Children.Add(matches_value);
                panel.Children.Add(won);
                panel.Children.Add(won_value);
                panel.Children.Add(lost);
                panel.Children.Add(lost_val);
                panel.Children.Add(tired);
                panel.Children.Add(tired_val);
                panel.Children.Add(draw);
                panel.Children.Add(draw_val);
                panel.Children.Add(perc);
                panel.Children.Add(perc_val);
                //StackPanel sta = new StackPanel();
                list.Items.Add(panel);
                // sta.Children.Add(list);
                list.Height = 200;
                list.Width = 350;

                border.Child = panel;
                p.Child = border;
            }
            catch (Exception ksd)
            {
                MessageBox.Show("Please wait it is loading and  try again ");
            }

           
            

           

        }
        Popup p1 = new Popup();
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                button1.Background = new SolidColorBrush(Colors.Green);
                button2.Background = new SolidColorBrush(Colors.DarkGray);
                button3.Background = new SolidColorBrush(Colors.Green);
                button4.Background = new SolidColorBrush(Colors.Green);

                App cuntry = App.Current as App;
                int index_c = cuntry.country_selcted;
                pppp.IsOpen = false;
                p2.IsOpen = false;
                p.IsOpen = false;
                p1.IsOpen = true;
                Border border = new Border();
                border.BorderBrush = new SolidColorBrush(Colors.Black);
                border.BorderThickness = new Thickness(5.0);
                //border.Height = 100;
                // border.Width = 200;
                border.Margin = new Thickness(40, 250, 0, 0);
                StackPanel panel = new StackPanel();
                panel.Height = 450;
                panel.Width = 400;
                panel.Background = new SolidColorBrush(Colors.LightGray);
                Odcrick tea;
                tea = odcri.ElementAt(index_c);
                TextBlock span = new TextBlock();
                span.Name = "span";
                span.Text = "SPAN";
                span.FontSize = 26;
                span.Margin = new Thickness(26, 30, 0, 0);
                span.HorizontalAlignment = HorizontalAlignment.Left;
                TextBlock span_value = new TextBlock();
                span_value.Name = "span_value";
                span_value.Text = tea.span;
                span_value.FontSize = 26;
                span_value.Margin = new Thickness(0, -35, 23, 0);
                span_value.HorizontalAlignment = HorizontalAlignment.Right;
                TextBlock matches = new TextBlock();
                matches.Name = "matches";
                matches.Text = "MATCHES";
                matches.FontSize = 26;
                matches.Margin = new Thickness(26, 30, 0, 0);
                matches.HorizontalAlignment = HorizontalAlignment.Left;
                TextBlock matches_value = new TextBlock();
                matches_value.Name = "matches_value";
                matches_value.Text = tea.match;
                matches_value.FontSize = 26;
                matches_value.Margin = new Thickness(0, -35, 23, 0);
                matches_value.HorizontalAlignment = HorizontalAlignment.Right;
                TextBlock won = new TextBlock();
                won.Name = "won";
                won.Text = "WON";
                won.FontSize = 26;
                won.Margin = new Thickness(26, 30, 0, 0);
                won.HorizontalAlignment = HorizontalAlignment.Left;
                TextBlock won_value = new TextBlock();
                won_value.Name = "won_name";
                won_value.Text = tea.won;
                won_value.FontSize = 26;
                won_value.Margin = new Thickness(0, -35, 23, 0);
                won_value.HorizontalAlignment = HorizontalAlignment.Right;



                TextBlock lost = new TextBlock();
                lost.Name = "lost";
                lost.Text = "Lost";
                lost.HorizontalAlignment = HorizontalAlignment.Left;
                lost.FontSize = 26;
                lost.Margin = new Thickness(26, 30, 0, 0);
                TextBlock lost_val = new TextBlock();
                lost_val.Name = "lost_valu";
                lost_val.Text = tea.lost;
                lost_val.FontSize = 26;
                lost_val.Margin = new Thickness(0, -35, 23, 0);
                lost_val.HorizontalAlignment = HorizontalAlignment.Right;
                TextBlock tired = new TextBlock();
                tired.Name = "tired";
                tired.Text = "TIRED";
                tired.FontSize = 26;
                tired.Margin = new Thickness(26, 30, 0, 0);
                tired.HorizontalAlignment = HorizontalAlignment.Left;
                TextBlock tired_val = new TextBlock();
                tired_val.Name = "tired_val";
                tired_val.Text = tea.tied;
                tired_val.FontSize = 26;
                tired_val.Margin = new Thickness(0, -35, 23, 0);
                tired_val.HorizontalAlignment = HorizontalAlignment.Right;
                TextBlock draw = new TextBlock();
                draw.Name = "draw";
                draw.Text = "DRAW";
                draw.FontSize = 26;
                draw.Margin = new Thickness(26, 30, 0, 0);
                draw.HorizontalAlignment = HorizontalAlignment.Left;
                TextBlock draw_val = new TextBlock();
                draw_val.Name = "draw_name";
                draw_val.Text = tea.draw;
                draw_val.FontSize = 26;
                draw_val.Margin = new Thickness(0, -35, 23, 0);
                draw_val.HorizontalAlignment = HorizontalAlignment.Right;
                TextBlock perc = new TextBlock();
                perc.Text = "PERCENTAGE";
                perc.Name = "perc";
                perc.FontSize = 26;
                perc.Margin = new Thickness(26, 30, 0, 0);
                perc.HorizontalAlignment = HorizontalAlignment.Left;
                TextBlock perc_val = new TextBlock();
                perc_val.Name = "perc_val";
                perc_val.Text = tea.percentage;
                perc_val.FontSize = 26;
                perc_val.Margin = new Thickness(0, -35, 23, 0);
                perc_val.HorizontalAlignment = HorizontalAlignment.Right;




                panel.Children.Add(span);
                panel.Children.Add(span_value);
                panel.Children.Add(matches);
                panel.Children.Add(matches_value);
                panel.Children.Add(won);
                panel.Children.Add(won_value);
                panel.Children.Add(lost);
                panel.Children.Add(lost_val);
                panel.Children.Add(tired);
                panel.Children.Add(tired_val);
                panel.Children.Add(draw);
                panel.Children.Add(draw_val);
                panel.Children.Add(perc);
                panel.Children.Add(perc_val);
                border.Child = panel;
                p1.Child = border;
            }
            catch (Exception xx)
            {
                MessageBox.Show("Please wait it is Loading and try again");
            }
        }
        Popup p2 = new Popup();
        private void button3_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                button1.Background = new SolidColorBrush(Colors.Green);
                button2.Background = new SolidColorBrush(Colors.Green);
                button3.Background = new SolidColorBrush(Colors.DarkGray);
                button4.Background = new SolidColorBrush(Colors.Green);
                App cuntry = App.Current as App;
                int index_c = cuntry.country_selcted;
                pppp.IsOpen = false;
                p.IsOpen = false;
                p1.IsOpen = false;
                p2.IsOpen = true;
                Border border = new Border();
                border.BorderBrush = new SolidColorBrush(Colors.Black);
                border.BorderThickness = new Thickness(5.0);
                //border.Height = 100;
                // border.Width = 200;
                border.Margin = new Thickness(40, 250, 0, 0);
                StackPanel panel = new StackPanel();
                panel.Height = 450;
                panel.Width = 400;
                panel.Background = new SolidColorBrush(Colors.LightGray);
                T20 tea;
                tea = twenty.ElementAt(index_c);//t.ElementAt(2);
                TextBlock span = new TextBlock();
                span.Name = "span";
                span.Text = "SPAN";
                span.Margin = new Thickness(26, 30, 0, 0);
                span.FontSize = 26;
                span.HorizontalAlignment = HorizontalAlignment.Left;
                TextBlock span_value = new TextBlock();
                span_value.Name = "span_value";
                span_value.Text = tea.span;
                span_value.FontSize = 26;
                span_value.Margin = new Thickness(0, -35, 23, 0);
                span_value.HorizontalAlignment = HorizontalAlignment.Right;
                TextBlock matches = new TextBlock();
                matches.Name = "matches";
                matches.Text = "MATCHES";
                matches.FontSize = 26;
                matches.Margin = new Thickness(26, 30, 0, 0);
                matches.HorizontalAlignment = HorizontalAlignment.Left;
                TextBlock matches_value = new TextBlock();
                matches_value.Name = "matches_value";
                matches_value.Text = tea.matches;
                matches_value.FontSize = 26;
                matches_value.Margin = new Thickness(0, -35, 23, 0);
                matches_value.HorizontalAlignment = HorizontalAlignment.Right;
                TextBlock won = new TextBlock();
                won.Name = "won";
                won.Text = "WON";
                won.FontSize = 26;
                won.Margin = new Thickness(26, 30, 0, 0);
                won.HorizontalAlignment = HorizontalAlignment.Left;
                TextBlock won_value = new TextBlock();
                won_value.Name = "won_name";
                won_value.Text = tea.won;
                won_value.FontSize = 26;
                won_value.Margin = new Thickness(0, -35, 23, 0);
                won_value.HorizontalAlignment = HorizontalAlignment.Right;



                TextBlock lost = new TextBlock();
                lost.Name = "lost";
                lost.Text = "Lost";
                lost.HorizontalAlignment = HorizontalAlignment.Left;
                lost.FontSize = 26;
                lost.Margin = new Thickness(26, 30, 0, 0);
                TextBlock lost_val = new TextBlock();
                lost_val.Name = "lost_valu";
                lost_val.Text = tea.lost;
                lost_val.FontSize = 26;
                lost_val.Margin = new Thickness(0, -35, 23, 0);
                lost_val.HorizontalAlignment = HorizontalAlignment.Right;
                TextBlock tired = new TextBlock();
                tired.Name = "tired";
                tired.Text = "TIRED";
                tired.FontSize = 26;
                tired.Margin = new Thickness(26, 30, 0, 0);
                tired.HorizontalAlignment = HorizontalAlignment.Left;
                TextBlock tired_val = new TextBlock();
                tired_val.Name = "tired_val";
                tired_val.Text = tea.tied;
                tired_val.FontSize = 26;
                tired_val.Margin = new Thickness(0, -35, 23, 0);
                tired_val.HorizontalAlignment = HorizontalAlignment.Right;
                TextBlock draw = new TextBlock();
                draw.Name = "draw";
                draw.Text = "DRAW";
                draw.FontSize = 26;
                draw.Margin = new Thickness(26, 30, 0, 0);
                draw.HorizontalAlignment = HorizontalAlignment.Left;
                TextBlock draw_val = new TextBlock();
                draw_val.Name = "draw_name";
                draw_val.Text = tea.draw;
                draw_val.FontSize = 26;
                draw_val.Margin = new Thickness(0, -35, 23, 0);
                draw_val.HorizontalAlignment = HorizontalAlignment.Right;
                TextBlock perc = new TextBlock();
                perc.Text = "PERCENTAGE";
                perc.Name = "perc";
                perc.FontSize = 26;
                perc.Margin = new Thickness(26, 30, 0, 0);
                perc.HorizontalAlignment = HorizontalAlignment.Left;
                TextBlock perc_val = new TextBlock();
                perc_val.Name = "perc_val";
                perc_val.Text = tea.percentage;
                perc_val.FontSize = 26;
                perc_val.Margin = new Thickness(0, -35, 23, 0);
                perc_val.HorizontalAlignment = HorizontalAlignment.Right;





                panel.Children.Add(span);
                panel.Children.Add(span_value);
                panel.Children.Add(matches);
                panel.Children.Add(matches_value);
                panel.Children.Add(won);
                panel.Children.Add(won_value);
                panel.Children.Add(lost);
                panel.Children.Add(lost_val);
                panel.Children.Add(tired);
                panel.Children.Add(tired_val);
                panel.Children.Add(draw);
                panel.Children.Add(draw_val);
                panel.Children.Add(perc);
                panel.Children.Add(perc_val);
                border.Child = panel;
                p2.Child = border;
            }
            catch (Exception kkaa)
            {
                MessageBox.Show("Please it is loading and try again");
            }
        }
   //    public  ListBox list_players = new ListBox();
       
         
        List<string> player_names = new List<string>();
        List<string> player_id = new List<string>();
        Popup pppp = new Popup();
        ListBox list_players = new ListBox();
        bool flag = false;
        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            pppp.IsOpen = false;
            p.IsOpen = false;
            p1.IsOpen = false;
            p2.IsOpen = false;
            base.OnNavigatedFrom(e);
            flag = true;

        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (flag)
            {
                flag = false;
                pppp.IsOpen = true;
 
            }
            base.OnNavigatedTo(e);
        }

        private void button4_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                button1.Background = new SolidColorBrush(Colors.Green);
                button4.Background = new SolidColorBrush(Colors.DarkGray);
                button3.Background = new SolidColorBrush(Colors.Green);
                button2.Background = new SolidColorBrush(Colors.Green);
                App cuntry = App.Current as App;
                int index_c = cuntry.country_selcted;
                p.IsOpen = false;
                p1.IsOpen = false;
                p2.IsOpen = false;
                list_players = new ListBox();
                list_players.SelectionChanged += new SelectionChangedEventHandler(list_players_SelectionChanged);
                pppp.IsOpen = true;
                Border br = new Border();
                // br.Background = new SolidColorBrush(Colors.DarkGray);
                br.BorderBrush = new SolidColorBrush(Colors.Black);
                br.BorderThickness = new Thickness(0.0);
                br.Margin = new Thickness(40, 250, 0, 0);
                StackPanel stk = new StackPanel();
                player_names.Clear();
                stk.Height = 520;
                stk.Width = 400;

                list_players.Height = 520;
                list_players.Width = 400;
                ImageBrush brush = new ImageBrush();
                brush.ImageSource = new BitmapImage(new Uri("wood-ipad-background.jpg", UriKind.Relative));
                ContentPanel.Background = brush;
                // ImageSource ims = new BitmapImage(new Uri(@"wood-ipad-background.jpg", UriKind.Relative));
                //img.ImageSource = ims;
                // names.Background = brush;
                stk.Background = brush;
                br.Background = brush;
                // list_players.Background = brush;
                foreach (KeyValuePair<string, string> kvp in team_players_names.ElementAt(index_c))
                {
                    System.Diagnostics.Debug.WriteLine("player value is......" + kvp.Value + ".......player id is.........." + kvp.Key + "count value is....................." + team_players_names.ElementAt(0).Count);
                    player_names.Add(kvp.Key);
                    StackPanel names = new StackPanel();
                    names.Height = 70;

                    TextBlock txt = new TextBlock();
                    txt.FontSize = 26;
                    txt.Foreground = new SolidColorBrush(Colors.Brown);
                    txt.FontWeight = FontWeights.Bold;
                    txt.FontStyle = FontStyles.Normal;
                    txt.Text = kvp.Value;
                    txt.HorizontalAlignment = HorizontalAlignment.Center;
                    txt.VerticalAlignment = VerticalAlignment.Center;
                    Line separator = new Line();
                    separator.StrokeThickness = 3;
                    separator.Stroke = new SolidColorBrush(Colors.Green);
                    separator.X1 = 0;
                    separator.Y1 = 0;
                    separator.X2 = 480;
                    separator.Y2 = 0;

                    names.Children.Add(txt);
                    names.Children.Add(separator);


                    //  names.Background = brush;
                    list_players.Items.Add(names);


                }
                System.Diagnostics.Debug.WriteLine("length of player names is............." + player_names.Count);
                stk.Children.Add(list_players);
                br.Child = stk;
                pppp.Child = br;

            }
            catch (Exception kk)
            {
                MessageBox.Show("Please wait it is loading and try again ");
            }
        }

        private void teamspbr_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {

        }
            
    }
}